package com.chatSystem;

import java.awt.*;
import javax.swing.*;

public class Login {
    private JTextField textField= null;
    private JPasswordField pwdField = null;
    private ClientReadAndPrint.LoginListen listener=null;

    public Login(){
        init();
    }

    void init(){
        JFrame jFrame = new JFrame("Xuan的聊天器");
        jFrame.setBounds(600,250,300,180);
        jFrame.setResizable(false);

        JPanel headPanel = new JPanel();

        JLabel headLable =  new JLabel("         欢迎使用");
        headLable.setFont(new Font(null,2,30));
        headPanel.add(headLable);

        JPanel mainPanel = new JPanel();
        JLabel accountLable = new JLabel("  账 户:");
        textField = new JTextField(20);
        JLabel passwordLable = new JLabel("  密 码:");
        pwdField  = new JPasswordField(20);

        JButton loginButton = new JButton("登录");

        mainPanel.add(accountLable);
        mainPanel.add(textField);
        mainPanel.add(passwordLable);
        mainPanel.add(pwdField);
        mainPanel.add(loginButton);

        JPanel jPanel = new JPanel(new BorderLayout());
        jPanel.add(headLable,BorderLayout.NORTH);
        jPanel.add(mainPanel,BorderLayout.CENTER);

        //监听动作
        listener = new ClientReadAndPrint().new LoginListen();
        listener.setJTextField(textField);  // 调用PoliceListen类的方法
        listener.setJPasswordField(pwdField);
        listener.setJFrame(jFrame);
        pwdField .addActionListener(listener);  // 密码框添加监听
        loginButton.addActionListener(listener);  // 按钮添加监听

        jFrame.add(jPanel);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setVisible(true);

    }

}
